using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using GonzalesCore.CoreElements;
using GonzalesCore.CoreManagers;
using Kypris2.CoreElements;
using Kypris2.Utils;
using Jamila2.Tools;

public partial class GonzalesViewClaim : System.Web.UI.Page
{
    #region Variables

    protected PrivateLoginSession CurrentPrivateSession = null;
    protected LogManager CurLogManager = null;
    protected GonzalesClaimHeader ResultObj = null;

    #region ClaimHavingCreditCard
    protected bool ClaimHavingCreditCard
    {
        get
        {
            return (bool)ViewState["ClaimHavingCreditCard"];
        }

        set
        {
            ViewState["ClaimHavingCreditCard"] = value;
        }
    }
    #endregion

    #region CurrentClaimStatus

    protected GonzalesClaimHeader.TypeOfClaimStatus CurrentClaimStatus
    {
        get
        {
            return (GonzalesClaimHeader.TypeOfClaimStatus)ViewState["CurrentClaimStatus"];
        }

        set
        {
            ViewState["CurrentClaimStatus"] = value;
        }
    }

    #endregion

    #region ClaimInternalID
    protected string ClaimInternalID
    {
        get
        {
            return ViewState["ClaimInternalID"].ToString();
        }

        set
        {
            ViewState["ClaimInternalID"] = value;
        }
    }
    #endregion

    #region ResultTable
    protected DataTable ResultTable
    {
        get
        {
            return (DataTable)ViewState[GonzalesCommonNamingConvention.CurrentPrivateSessionViewState];
        }

        set
        {
            ViewState[GonzalesCommonNamingConvention.CurrentPrivateSessionViewState] = value;
        }
    }
    #endregion

    #region Common Variables for Language Translation

    #region ArrayListHeader
    protected ArrayList ArrayListHeader
    {
        get
        {
            return (ArrayList)ViewState["ArrayListHeader"];
        }

        set
        {
            ViewState["ArrayListHeader"] = value;
        }
    }
    #endregion

    #region Item_RejectedByFinance
    protected string Item_RejectedByFinance
    {
        get
        {
            return ViewState["Item_RejectedByFinance"].ToString();
        }

        set
        {
            ViewState["Item_RejectedByFinance"] = value;
        }
    }
    #endregion

    #region Item_RejectedByApprover
    protected string Item_RejectedByApprover
    {
        get
        {
            return ViewState["Item_RejectedByApprover"].ToString();
        }

        set
        {
            ViewState["Item_RejectedByApprover"] = value;
        }
    }
    #endregion

    #endregion

    #endregion

    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        this.SessionCheck();

        if (!IsPostBack)
        {
            #region Request.QueryString["id"]
            if (Request.QueryString["id"] != null && Request.QueryString["id"].Length == 36)
            {
                this.ClaimInternalID = Request.QueryString["id"];
            }
            else
            {
                Response.Redirect(GonzalesErrorPageRedirect.PageFlowError);
            }
            #endregion

            this.SwitchLanguage();
            this.PageComponentSetup();

            this.LoadData();

            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView);
        }
    }
    protected void DropDownList_SortBy_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ResultTable != null)
        {
            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView);
        }
    }
    protected void DropDownList_SortOrder_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.DropDownList_SortBy_SelectedIndexChanged(sender, e);
    }

    #region OnRowCreated
    protected void OnRowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TableCellCollection cells = e.Row.Cells;

            for (int i = 0; i < this.ArrayListHeader.Count; i++)
            {
                cells[i].Text = this.ArrayListHeader[i].ToString();
            }
        }
    }
    #endregion
    #endregion

    #region Customized Methods

    #region SessionCheck
    public void SessionCheck()
    {

        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
            this.CurLogManager = new LogManager(this.CurrentPrivateSession);    // activate Log Manager
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }

    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    {
        this.Button_FileManager.Attributes["onclick"] = "ShowModal('FileManager', '', 'id=" + this.ClaimInternalID + "&NoEdit=1'); return false;";
        this.Button1.Attributes["onclick"] = "ShowModal('FileManager', '', 'id=" + this.ClaimInternalID + "&NoEdit=1'); return false;";
        this.Button_Print.Attributes["onclick"] = "print();return false;";
        this.Button2.Attributes["onclick"] = "print();return false;";
        this.Button_PrinterFriendlyNameList1.Attributes["onclick"] = "var windetail = window.open('GonzalesViewClaimNameList.aspx?id=" + this.ClaimInternalID + "','','scrollbars=yes,width=800,height=600'); return false;";
        this.Button_PrinterFriendlyNameList.Attributes["onclick"] = "var windetail = window.open('GonzalesViewClaimNameList.aspx?id=" + this.ClaimInternalID + "','','scrollbars=yes,width=800,height=600'); return false;";
    }
    #endregion

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        try
        {
            using (MultiLingualFactory CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID))
            {


                this.Label_PageTitle.Text = CurLanguageFactory.DisplayValue("PageTitle");
                this.Label_Approver.Text = CurLanguageFactory.DisplayValue("Approver") + ":";
                this.Label_ClaimNum.Text = CurLanguageFactory.DisplayValue("ClaimNum") + ":";
                this.Label_EmployeeName.Text = CurLanguageFactory.DisplayValue("EmployeeName") + ":";
                this.Label_EmployeeNo.Text = CurLanguageFactory.DisplayValue("EmployeeNo") + ":";
                this.Label_OwningEmployee.Text = CurLanguageFactory.DisplayValue("OwningEmployee");
                this.Label_ProfitCenter.Text = CurLanguageFactory.DisplayValue("ProfitCenter") + ":";
                this.Label_Purpose.Text = CurLanguageFactory.DisplayValue("Purpose") + ":";
                this.Label_Status.Text = CurLanguageFactory.DisplayValue("Status") + ":";
                this.Label_TotalAmount.Text = CurLanguageFactory.DisplayValue("TotalAmount");
                this.Label_TotalAmountLessPaid.Text = CurLanguageFactory.DisplayValue("TotalAmountLessPaid");
                this.Label1.Text = CurLanguageFactory.DisplayValue("Label1");
                this.Label3.Text = CurLanguageFactory.DisplayValue("Label3");
                this.Label5.Text = CurLanguageFactory.DisplayValue("Label5");
                this.Button_Print.Text = CurLanguageFactory.DisplayValue("Print");
                this.Button_PrinterFriendlyNameList.Text = CurLanguageFactory.DisplayValue("PrinterFriendlyNameList");
                this.Button_PrinterFriendlyNameList1.Text = CurLanguageFactory.DisplayValue("PrinterFriendlyNameList1");
                this.Button1.Text = CurLanguageFactory.DisplayValue("Button1");
                this.Button2.Text = CurLanguageFactory.DisplayValue("Button2");
                this.Button_FileManager.Text = CurLanguageFactory.DisplayValue("FileManager");
                this.Item_RejectedByApprover = CurLanguageFactory.DisplayValue("RejectedByApprover") + ":";
                this.Item_RejectedByFinance = CurLanguageFactory.DisplayValue("RejectedByFinance") + ":";
                this.Label_ActionLog.Text = CurLanguageFactory.DisplayValue("ActionLog");

                this.ArrayListHeader = new ArrayList();
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ExpenseDetail"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue(""));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue(""));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("Description"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("Remarks"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("DetailDateInStr"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("Location"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("City"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ClaimedAmountInStr"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("Tax"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ExRateCurrency"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ExRate"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("LocalAmountInStr"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("FinalAmountInStr"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ProjectID"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ChargeToProfitCenter"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ChargeToEmployeeID"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ShowDetail"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("ApproverRemarks"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("FinanceRemarks"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("AuthorizerRemarks"));
                this.ArrayListHeader.Add(CurLanguageFactory.DisplayValue("FinanceApproverRemarks"));


                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ExpenseDetail"), "ExpenseDetail"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Description"), "Description"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Remarks"), "Remarks"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("DetailDateInStr"), "DetailDate"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Location"), "Location"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("City"), "City"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ClaimedAmountInStr"), "ClaimedAmount"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ExRateCurrency"), "ExRateCurrency"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ExRate"), "ExRate"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("LocalAmountInStr"), "LocalAmount"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ProjectID"), "ProjectID"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ChargeToProfitCenter"), "ChargeToProfitCenter"));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ChargeToEmployeeID"), "ChargeToEmployeeID"));

                this.DropDownList_SortBy.Items.FindByValue("DetailDate").Selected = true;

                this.DropDownList_SortOrder.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ASC"), "ASC"));
                this.DropDownList_SortOrder.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("DESC"), "DESC"));

            }
        }
        catch (Exception ex)
        {
            this.CurLogManager.LogError("[GonzalesViewClaim.SwitchLanguage.EX] : " + ex.Message, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }

    }
    #endregion

    #endregion

    #region Data Operation

    #region LoadData
    protected void LoadData()
    {
        using (ClaimManager CurClaimManager = new ClaimManager(this.CurrentPrivateSession))
        {
            ResultObj = CurClaimManager.GetClaimByInternalID(this.ClaimInternalID);
            ResultObj.ClaimDetails = CurClaimManager.GetClaimItemsByClaimHeaderInLang(this.ClaimInternalID, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage);
            ResultObj.ClaimDetails.SortByOrder();

            this.CurrentClaimStatus = ResultObj.Status;

            using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
            {
                this.ResultObj.ClaimedBy = CurUserManager.GetUserByInternalID(this.ResultObj.ClaimedBy.InternalID);
            }

            // fill in the blank
            this.LabelValue_EmployeeName.Text = ResultObj.ClaimedBy.DisplayName + " (" + ResultObj.ClaimedBy.EmailID + ")";
            this.LabelValue_EmployeeNo.Text = ResultObj.ClaimedBy.EmployeeID;
            this.LabelValue_ClaimNo.Text = ResultObj.ClaimID;
            this.LabelValue_Purpose.Text = ResultObj.Reasons;
            this.LabelValue_Status.Text = ClaimManager.GetClaimStatusInString(ResultObj.Status);
            this.LabelValue_ProfitCenter.Text = ResultObj.ClaimedBy.CostCenter;            

            #region Status & Related Personnel

            using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
            {
                SystemUser CurUserObj = null;

                if (ResultObj.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByApprover)
                {
                    CurUserObj = CurUserManager.GetUserByInternalID(ResultObj.LastUpdatedBy.InternalID);

                    this.Label_Approver.Text = this.Item_RejectedByApprover;
                    this.LabelValue_Approver.Text = CurUserObj.DisplayName;
                }
                else if (ResultObj.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByAuthorizer)
                {
                    CurUserObj = CurUserManager.GetUserByInternalID(ResultObj.LastUpdatedBy.InternalID);

                    this.Label_Approver.Text = this.Item_RejectedByFinance;
                    this.LabelValue_Approver.Text = CurUserObj.DisplayName;
                }
                else if (ResultObj.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinance)
                {
                    CurUserObj = CurUserManager.GetUserByInternalID(ResultObj.LastUpdatedBy.InternalID);

                    this.Label_Approver.Text = this.Item_RejectedByFinance;
                    this.LabelValue_Approver.Text = CurUserObj.DisplayName;
                }
                else if (ResultObj.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApprover)
                {
                    CurUserObj = CurUserManager.GetUserByInternalID(ResultObj.LastUpdatedBy.InternalID);

                    this.Label_Approver.Text = this.Item_RejectedByFinance;
                    this.LabelValue_Approver.Text = CurUserObj.DisplayName;
                }
                else if (ResultObj.Status == GonzalesClaimHeader.TypeOfClaimStatus.Submitted)
                {
                    CurUserObj = CurUserManager.GetUserByInternalID(ResultObj.NextApprover.InternalID);

                    this.LabelValue_Approver.Text = CurUserObj.DisplayName;
                }
                else
                {
                    if (ResultObj.NextApprover != null)
                    {
                        CurUserObj = CurUserManager.GetUserByInternalID(ResultObj.NextApprover.InternalID);
                        this.LabelValue_Approver.Text = CurUserObj.DisplayName;

                    }
                }

            }

            #endregion

            // total
            this.LabelValue_TotalLocalAmount.Text = (ResultObj.FinalApprovedAmount != 0) ? ResultObj.FinalApprovedAmount.ToString(GonzalesGeneralVariables.CurrencyFormat) : ResultObj.TotalClaimedAmount.ToString(GonzalesGeneralVariables.CurrencyFormat);
            this.LabelValue_TotalAmountPaid.Text = ResultObj.TotalLocalAmountAlreadyPaid.ToString(GonzalesGeneralVariables.CurrencyFormat);
            this.LabelValue_Owning.Text = ResultObj.TotalLocalActualAmountLeft.ToString(GonzalesGeneralVariables.CurrencyFormat);

            //total
            this.LabelValue_TotalLocalAmount2.Text = (ResultObj.FinalApprovedAmount != 0) ? ResultObj.FinalApprovedAmount.ToString(GonzalesGeneralVariables.CurrencyFormat) : ResultObj.TotalClaimedAmount.ToString(GonzalesGeneralVariables.CurrencyFormat);
            this.LabelValue_TotalAmountPaid2.Text = ResultObj.TotalLocalAmountAlreadyPaid.ToString(GonzalesGeneralVariables.CurrencyFormat);
            this.LabelValue_Owning2.Text = ResultObj.TotalLocalActualAmountLeft.ToString(GonzalesGeneralVariables.CurrencyFormat);

            decimal TotalPersonalExpenses = 0;

            // claim detail
            if (ResultObj.ClaimDetails != null)
            {
                this.ResultTable = new DataTable();
                ResultTable.Columns.Add(new DataColumn("ExpenseDetail", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("Description", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("Remarks", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("DetailDate", Type.GetType("System.DateTime")));
                ResultTable.Columns.Add(new DataColumn("DetailDateInStr", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("DetailType", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("IsPersonal", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("Location", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("City", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("Tax", Type.GetType("System.Decimal")));
                ResultTable.Columns.Add(new DataColumn("ClaimedAmount", Type.GetType("System.Decimal")));
                ResultTable.Columns.Add(new DataColumn("ClaimedAmountInStr", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("ExRateCurrency", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("ExRate", Type.GetType("System.Decimal")));
                ResultTable.Columns.Add(new DataColumn("LocalAmount", Type.GetType("System.Decimal")));
                ResultTable.Columns.Add(new DataColumn("LocalAmountInStr", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("FinalAmount", Type.GetType("System.Decimal")));
                ResultTable.Columns.Add(new DataColumn("FinalAmountInStr", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("ProjectID", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("ChargeToProfitCenter", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("ChargeToEmployeeID", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("ApproverRemarks", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("FinanceRemarks", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("AuthorizerRemarks", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("FinanceApproverRemarks", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("ApproverState", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("FAState", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("AuthorizerState", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("FinanceApprState", Type.GetType("System.String")));
                ResultTable.Columns.Add(new DataColumn("ShowDetail", Type.GetType("System.String")));

                DataRow RowObj = null;
                this.ClaimHavingCreditCard = false;

                for (int x = 0; x < ResultObj.ClaimDetails.Count; x++)
                {
                    GonzalesClaimItem CurClaimItem = (GonzalesClaimItem)ResultObj.ClaimDetails[x];
                    RowObj = ResultTable.NewRow();

                    this.ClaimHavingCreditCard = (CurClaimItem.ClaimDetailType == TypeOfClaimDetail.CreditCard) ? true : this.ClaimHavingCreditCard;

                    RowObj["ExpenseDetail"] = CurClaimItem.ClaimType.DisplayName;
                    RowObj["Description"] = CurClaimItem.Description;
                    RowObj["Remarks"] = CurClaimItem.Remarks;
                    RowObj["DetailDate"] = CurClaimItem.ClaimDate;
                    RowObj["DetailDateInStr"] = SwissArmy.DateConvert(CurClaimItem.ClaimDate, this.CurrentPrivateSession.DateFormatInUse, "/");
                    RowObj["Tax"] = CurClaimItem.Tax;
                    RowObj["ClaimedAmount"] = CurClaimItem.ClaimedAmount;
                    RowObj["ClaimedAmountInStr"] = CurClaimItem.ClaimedAmount.ToString(GonzalesGeneralVariables.CurrencyFormat);
                    RowObj["DetailType"] = (CurClaimItem.ClaimDetailType == TypeOfClaimDetail.CreditCard) ? "<img src='" + GonzalesImages.Icon_CreditCard + "'>" : "";
                    RowObj["IsPersonal"] = (CurClaimItem.IsPersonnal) ? "<img src='" + GonzalesImages.Icon_Personal + "'>" : "";
                    RowObj["Location"] = CurClaimItem.Country.DisplayName;
                    RowObj["City"] = CurClaimItem.City;
                    RowObj["ExRateCurrency"] = CurClaimItem.ExchangeCurrency.DisplayName;
                    RowObj["ExRate"] = CurClaimItem.ExchangeRate;
                    RowObj["LocalAmount"] = CurClaimItem.AmountOut;
                    RowObj["LocalAmountInStr"] = CurClaimItem.AmountOut.ToString(GonzalesGeneralVariables.CurrencyFormat);
                    RowObj["FinalAmount"] = CurClaimItem.AmountFinal;
                    RowObj["FinalAmountInStr"] = CurClaimItem.AmountFinal.ToString(GonzalesGeneralVariables.CurrencyFormat);
                    RowObj["ProjectID"] = CurClaimItem.ProjectID;
                    RowObj["ChargeToProfitCenter"] = CurClaimItem.ChargeToProfitCenter;
                    RowObj["ChargeToEmployeeID"] = CurClaimItem.ChargeToEmployeeiD;
                    RowObj["ApproverRemarks"] = CurClaimItem.ApproverRemarks;
                    RowObj["FinanceRemarks"] = CurClaimItem.FinanceRemarks;
                    RowObj["AuthorizerRemarks"] = CurClaimItem.AuthorizerRemarks;
                    RowObj["FinanceApproverRemarks"] = CurClaimItem.FinanceApproverRemarks;
                    RowObj["ApproverState"] = (CurClaimItem.ApproverState) ? "<img src='" + GonzalesImages.Icon_Checked + "'>" : "<img src='" + GonzalesImages.Icon_Crossed + "'>";
                    RowObj["FAState"] = (CurClaimItem.FinanceState) ? "<img src='" + GonzalesImages.Icon_Checked + "'>" : "<img src='" + GonzalesImages.Icon_Crossed + "'>";
                    RowObj["AuthorizerState"] = (CurClaimItem.AuthorizerState) ? "<img src='" + GonzalesImages.Icon_Checked + "'>" : "<img src='" + GonzalesImages.Icon_Crossed + "'>";
                    RowObj["FinanceApprState"] = (CurClaimItem.FinanceApproverState) ? "<img src='" + GonzalesImages.Icon_Checked + "'>" : "<img src='" + GonzalesImages.Icon_Crossed + "'>";
                    RowObj["ShowDetail"] = (CurClaimItem.Remarks.IndexOf("[ENT]") >= 0) ? "<a href='#' onclick=\"ShowSpecialPopOut('" + CurClaimItem.ClaimType.GLCode + "', null, 'NoEdit=1&id=" + this.ClaimInternalID + "&did=" + CurClaimItem.InternalID + "&remarks=" + CurClaimItem.Remarks.Replace("'", "#") + "');\"><img border='0' src='" + GonzalesImages.Icon_Detail + "'></a>" : "";

                    if (CurClaimItem.ClaimDetailType == TypeOfClaimDetail.CreditCard && CurClaimItem.IsPersonnal)
                        TotalPersonalExpenses -= CurClaimItem.AmountOut;

                    ResultTable.Rows.Add(RowObj);
                }

                this.LabelValue_TotalPersonalExpenses.Text = TotalPersonalExpenses.ToString(GonzalesGeneralVariables.CurrencyFormat);

                GonzalesClaimHeader CurrentClaimHeader = (GonzalesClaimHeader)ResultObj;

                this.GridViewResult.Columns[1].Visible = this.GridViewResult.Columns[2].Visible = ClaimHavingCreditCard;
                this.GridViewResult.Columns[13].Visible = (CurrentClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.Verified || CurrentClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.SubmittedForPayment);
                this.GridViewResult.Columns[18].Visible = this.GridViewResult.Columns[22].Visible = (CurrentClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByApprover);
                this.GridViewResult.Columns[19].Visible = this.GridViewResult.Columns[23].Visible = (CurrentClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinance);
                this.GridViewResult.Columns[20].Visible = this.GridViewResult.Columns[24].Visible = (CurrentClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByAuthorizer);
                this.GridViewResult.Columns[21].Visible = this.GridViewResult.Columns[25].Visible = (CurrentClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApprover);

                #region Action Log

                LogsCollection ActionLogs = this.CurLogManager.GetActionLogByClaimID(this.ClaimInternalID);
                if (ActionLogs != null)
                {
                    StringBuilder ActionLogBuilder = new StringBuilder();

                    #region Status

                    for (int x = 0; x < ActionLogs.Count; x++)
                    {
                        ActionLogItem CurLogItem = (ActionLogItem)ActionLogs[x];
                        string Status = "";

                        switch (CurLogItem.ActionDescription)
                        {
                            case "Claim Created":
                                Status = "Claim created on";
                                break;

                            case "Claim Submitted":
                                Status = "Claim submitted on";
                                break;

                            case "Claim Saved":
                                Status = "Claim saved on";
                                break;

                            case "Claim Approved":
                                Status = "Claim approved on";
                                break;

                            case "Claim Authorized":
                                Status = "Claim authorized on";
                                break;

                            case "Claim Verified":
                                Status = "Claim verified on";
                                break;

                            case "Claim Finance Approved":
                                Status = "Claim approved (Finance Approver) on";
                                break;

                            case "Claim Rejected By Approver":
                                Status = "Claim rejected (Approver) on";
                                break;

                            case "Claim Rejected By Authorizer":
                                Status = "Claim rejected (Authorizer) on";
                                break;

                            case "Claim Rejected By FinanceAdmin":
                                Status = "Claim rejected (Finance Admin) on";
                                break;

                            case "Claim Rejected By FinanceApprover":
                                Status = "Claim rejected (Finance Approver) on";
                                break;

                            //added by mei chze on 23072012
                            case "Claim Status Change By System Admin":
                                Status = "Claim Status Change on";
                                break;
                        }                        

                        ActionLogBuilder.AppendLine(Status + " " + SwissArmy.DateConvert(CurLogItem.LogDate, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedDateFormat, "/", true) + " by " + CurLogItem.LoggedBy.DisplayName);

                        TableCell TableCellHistory = new TableCell();
                        TableCellHistory.CssClass = "GridViewItem";
                        TableCellHistory.Text = Status + " " + SwissArmy.DateConvert(CurLogItem.LogDate, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedDateFormat, "/", true) + " by " + CurLogItem.LoggedBy.DisplayName;

                        TableRow TableRowHistory = new TableRow();
                        TableRowHistory.Cells.Add(TableCellHistory);

                        this.Table_History.Rows.Add(TableRowHistory);
                    }

                    #endregion

                    this.Image_ActionLog.ToolTip = ActionLogBuilder.ToString();
                    this.Image_ActionLog.Attributes["onclick"] = "alert(this.title);";

                }
                else
                {
                    string LogID = SwissArmy.UniqueID();
                    this.CurLogManager.LogError(LogID, "[GonzalesMyClaimDetail.LoadData] : Failed at this.CurLogManager.GetActionLogByClaimID('" + this.ClaimInternalID + "') : " + this.CurLogManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }

                #endregion

            }

        }

        #region Supporting Documents

        using (FileManager CurFileManager = new FileManager(this.CurrentPrivateSession))
        {
            SupportingDocuments ListOfDocs = CurFileManager.GetFilesByClaimID(this.ClaimInternalID);
            if (ListOfDocs != null)
            {
                this.Button_FileManager.Text += " (" + ListOfDocs.Count + ")";
                this.Button1.Text += " (" + ListOfDocs.Count + ")";
            }
            else
            {
                this.Button_FileManager.Text += " (0)";

                string ErrorID = SwissArmy.UniqueID();
                this.CurLogManager.LogError(ErrorID, "[GonzalesMyClaimDetail.LoadData] : Failed at CurFileManager.GetFilesByClaimID(" + this.ClaimInternalID + ") : " + CurFileManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
            }
        }

        #endregion
    }

    #endregion



    private void BindData(DataView result)
    {
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    private void BindData(DataView result, int pageindex)
    {
        this.GridViewResult.PageIndex = pageindex;
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    #endregion

    protected void CheckUncheckAll(object sender, EventArgs e)
    {
        //FRANK add checkall: 20130122
        //CheckBox chk1 ;
        //chk1 = (CheckBox)GridViewResult.HeaderRow.Cells(0).FindControl("CheckBox1");
        //foreach (GridViewRow row in GridViewResult.Rows)
        //{
        //    CheckBox chk = default(CheckBox);
        //    chk = (CheckBox)row.Cells(0).FindControl("CheckBox2");
        //    chk.Checked = chk1.Checked;
        //}
    }
}
